﻿using KamRemakeRemake.Common;
using KamRemakeRemake.GameObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using KamRemakeRemake.GameObjects.UnitObjects.Units;

namespace KamRemakeRemake.Graphics {
    /// <summary>
    /// This class is responsible for drawing the various units
    /// </summary>
    public class UnitSprite : IDrawableGameObject{
        /// <summary>
        /// Path where all unit sprites are stored
        /// </summary>
        private const string SPRITEPATH = "sprites/units/";

        /// <summary>
        /// Returns the path to the sprites of the current units, for example for knights: sprites/units/Knight/...
        /// </summary>
        private string SpritePath {
            get {
                return SPRITEPATH + this.Unit.SpriteBaseName + "/";
            }
        }

        /// <summary>
        /// The unit we are drawing
        /// </summary>
        public Unit Unit { get; set; }

        protected AnimatedSprite currentSprite;
        protected Texture2D walkAnimationTexture;
        public UnitSprite(Unit unit) {
            this.Unit = unit;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, ContentManager contentManager) {
            this.currentSprite.Draw(spriteBatch, this.Unit.Position);
        }

        public void LoadContent(ContentManager contentManager) {
            this.walkAnimationTexture = contentManager.Load<Texture2D>(SpritePath + "walksouth");
            this.currentSprite = new AnimatedSprite(this.walkAnimationTexture, 2, 3);
        }

        public void Update(GameTime gameTime) {
            this.currentSprite.Update(gameTime);
        }
    }
}
